package com.situ.storehouse.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class ImageUtil {

	public static BufferedImage image(String code) {
		int width = 250, height = 100;
		//rgb不透明色
		BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		Graphics g = bi.getGraphics();
		
		// 设置背景
		g.setColor(new Color(230, 230, 230));
		g.fillRect(0, 0, width, height);

		// 画干扰线
		g.setColor(new Color(180, 180, 180));
		g.drawLine(0, 0, 250, 100);
		g.drawLine(0, 100, 250, 0);
		g.drawLine(190, 130, 250, 100);
		g.drawLine(198, 100, 250, 0);
		g.drawLine(200, 100, 200, 100);
		
		// 设置颜色，字体，写出内容
		g.setColor(new Color(30, 30, 30));
		g.setFont(new Font("Times New Roman", Font.PLAIN, 80));
		g.drawString(code, 10, 80);
		

		// 生成图像
		g.dispose();
		return bi;
	}

}
